package com.ingenieria.industrial.dao.implementacion;

import com.ingenieria.industrial.dao.diseño.IFormatoDAO;
import com.ingenieria.industrial.dto.Formato;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class FormatoDAO extends BaseDAO implements IFormatoDAO {

    private Connection cn = null;
    private PreparedStatement ps = null;
    private ResultSet rs = null;
    private String sqlQuery = null;

    public FormatoDAO(Connection cnx) {
        super(cnx);
    }

    @Override
    public Formato getByCodProc(String cod_proc) throws SQLException {
        sqlQuery = " SELECT * FROM t_documentos d "
                + " INNER JOIN t_formatos f ON d.codigo = f.cod_for "
                + " WHERE f.cod_proc = ?";
        Formato formato = null;
        try {
            int pos = 1;
            cn = ConexionDB.getConnection();
            ps = cn.prepareStatement(sqlQuery);
            ps.setString(pos++, cod_proc);
            rs = ps.executeQuery();
            while (rs.next()) {
                formato = new Formato();
                mapearBeanForRS(rs, formato);
            }
        } catch (SQLException e) {
            formato = null;
        } finally {
            try {
                if (cn != null) {
                    cn.close();
                }
                if (ps != null) {
                    ps.close();
                }
                if (rs != null) {
                    rs.close();
                }
            } catch (SQLException e) {
            }
        }
        return formato;
    }

}
